/*
 * ====================================================================
 * Copyright (c) 2002-2018 The RapidSVN Group.  All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program (in the file GPL.txt).
 * If not, see <http://www.gnu.org/licenses/>.
 *
 * This software consists of voluntary contributions made by many
 * individuals.  For exact contribution history, see the revision
 * history and logs, available at http://rapidsvn.tigris.org/.
 * ====================================================================
 */
#ifndef _MAIN_FRAME_HEADER_H_INCLUDED_
#define _MAIN_FRAME_HEADER_H_INCLUDED_

// wxWidgets
#include "wx/frame.h"
#include "wx/textctrl.h"
#include "wx/toolbar.h"

// svncpp
#include "svncpp/targets.hpp"

// app
#include "action_worker.hpp"
#include "tracer.hpp"
#include "log_action.hpp"
#include "rapidsvn_generated.h"
#include "utils.hpp"
#include "MyTray.h"
//#include "GitContext.h"

typedef enum {
    ACTIVE_PANE_FOLDER_BROWSER,
    ACTIVE_PANE_FILE_LIST
}
        ActivePane;

// forward declarations
class wxFrame;
class wxMenu;
class wxString;
class wxListEvent;
class MyTagApp;
class MyTray;
class WifiMonitor;

class MainFrame : public MainFrameBase
{
public:
    /**
     * Constructor that will be called by the App
     *
     * @param title Application title
     * @param locale The locale that's used by the app
     */
    MainFrame ( MyTagApp* myTagApp, const wxString & title,
                const wxLocale & locale );
    //FolderBrowser
    ~MainFrame() override;

    /** Allow children to trim their popup menus using the frames logic */
    void   TrimDisabledMenuItems ( wxMenu & menu );

    /**
    * Change the active window, if the corresponding event is handled
    * in one of the sub-windows
    */
    void   SetActivePane ( ActivePane value );

    /** disallow default constructor */
    MainFrame() = delete;

    /** disallow copy constructor */
    MainFrame ( const MainFrame & ) =delete;
private:
    MyTagApp* myTagApp;
    MyTray* myTray;

    void OnFocusChanged ( wxCommandEvent & event );

    // File menu
    void OnAddWcBookmark ( wxCommandEvent & event );
    //git
    void OnAddGitWcBookmark ( wxCommandEvent & event );

    void OnAddRepoBookmark ( wxCommandEvent & event );
    void OnRemoveBookmark ( wxCommandEvent & event );
    void OnEditBookmark ( wxCommandEvent & event );
    void OnQuit ( wxCommandEvent & event );
    //git
    void OnCloneGit ( wxCommandEvent & event );
    void OnGitCommit ( wxCommandEvent & event );
    void OnGitPush ( wxCommandEvent & event );
    void OnGitAddAll ( wxCommandEvent & event );

    //misc
    void OnQueryGitIP ( wxCommandEvent & event );
    void OnWifiChangeNotification ( wxCommandEvent & event );
    void OnMyLogMonitor (wxCommandEvent &);
    //
    void OnExPreference( wxCommandEvent & event );

    // View menu
    void OnPreferences ( wxCommandEvent & event );
    void OnRefresh ( wxCommandEvent & event );
    void OnColumnReset ( wxCommandEvent & event );
    void OnColumn ( wxCommandEvent & event );
    void OnIncludePath ( wxCommandEvent & event );
    void OnSortAscending ( wxCommandEvent & event );
    void OnColumnSorting ( wxCommandEvent & event );
    void OnFlatView ( wxCommandEvent & event );
    void OnRefreshWithUpdate ( wxCommandEvent & event );
    void OnShowUnVersioned ( wxCommandEvent & );
    void OnShowUnmodified ( wxCommandEvent & event );
    void OnShowModified ( wxCommandEvent & event );
    void OnShowConflicted ( wxCommandEvent & event );
    void OnIgnoreExternals ( wxCommandEvent & event );
    void OnShowIgnored ( wxCommandEvent & event );
    void OnStop ( wxCommandEvent & event );
    void OnIndicateModifiedChildren ( wxCommandEvent & event );

    // Query menu
    void OnLog ( wxCommandEvent & event );
    void OnInfo ( wxCommandEvent & event );

    // Modify menu
    void OnFileCommand ( wxCommandEvent & event );

    // Extras menu
    void OnCleanup ( wxCommandEvent & event );

    // Help menu
    void OnHelpContents ( wxCommandEvent & event );
    void OnHelpIndex ( wxCommandEvent & event );
    void OnHelpStartupTips ( wxCommandEvent & event );
    void OnAbout ( wxCommandEvent & event );

    // Test menu
    void OnTestNewWxString ( wxCommandEvent & event );
    void OnTestListener ( wxCommandEvent & event );
    void OnTestCheckout ( wxCommandEvent & event );
    void PrintTimeMeasurements ( apr_time_t start, apr_time_t end,
                                 const wxString & name );
    void OnTestCertDlg ( wxCommandEvent & event );
    void OnTestDestinationDlg ( wxCommandEvent & event );
    void OnTestDndDlg ( wxCommandEvent & event );

    // toolbar events
    void OnToolEnter ( wxCommandEvent & event );

    // log toolbar events
    void OnLogClear ( wxCommandEvent & event );
    void OnLogToggle ( wxCommandEvent & event );
    void OnLogUpdate ( wxUpdateUIEvent & event );
    // Events from action threads
    void OnActionEvent ( wxCommandEvent & event );
    void OnListenerEvent ( wxCommandEvent & event );

    // Bookmarks
    void AddWcBookmark();
    void AddGitWcBookmark();
    void AddRepoBookmark();
    void RemoveBookmark();
    void EditBookmark();
    void CloneGitRepository();

    // Authentication
    void OnLogin ( wxCommandEvent & event );
    void OnLogout ( wxCommandEvent & event );

    // Folder Browser event handlers
    void OnFolderBrowserSelChanged ( wxTreeEvent & event );
    void OnFolderBrowserKeyDown ( wxTreeEvent & event );

    // File List event handlers
    void OnFileListSelected ( wxListEvent & event );

    // Log list event handlers
    void OnLogListBrowse ( wxCommandEvent & event );
    void OnLogListDiff ( wxCommandEvent & event );

    void OnClickMyTray( wxTaskBarIconEvent& event );
    void OnClose( wxCloseEvent&  event );
    /**
     * Invoke the default action on the currently selected item(s)
     *
     * For folders, this is to open them within RapidSVN. For files, this is to
     * activate the default external editor.
     *
     * @return false if no items were found to invoke default action on
     */
    bool InvokeDefaultAction();

    /**
     * Update the contents of the filelist
     */
    void RefreshFileList();

    /**
     * Update the contents of the folder browser
     */
    void RefreshFolderBrowser();

    // Auxiliary functions
    void UpdateCurrentPath();
    void UpdateMenuSorting();
    void UpdateMenuIncludePath();
    void UpdateMenuAscending();
    void SetIncludePathVisibility ( bool flatMode );

    // Enable/disable action menu items
    void OnUpdateCommand ( wxUpdateUIEvent & updateUIEvent );

    // Utility functions
    void ShowLog();
    void ShowInfo();

    void DelEntries();
    void MakeRevert();
    void MakeResolve();

    void MakeCopy();
    void Rename();
    void Mkdir();
    void Merge();
    void Contents();
    void ShowPreferences();

    void PerformAction (SvnAction * action );
    void PerformAction (NormalAction * action );
    void Perform (AbstractAction * action );

    void OnIdle ( wxIdleEvent& event );
protected: // inherited from MainFrameBase
    void OnActivate ( wxActivateEvent & event ) override;
    void OnSize ( wxSizeEvent & sizeEvent ) override;
    void OnFolderBrowserSetFocus ( wxFocusEvent& event ) override;
    void OnListCtrlSetFocus ( wxFocusEvent& event ) override;
private:
    /** hide implementation data */
    struct ViewHolder;
    ViewHolder * viewHolder;

    //ActionWorker * m_actionWorker;
    ActionWorker* m_actionWorker;

    wxString m_title;
    svn::Context * m_svn_context;

    //GitContext * m_git_context;
private:
    //callback list
    void OnWifiMonitor( wxCommandEvent & WXUNUSED ( event ) );
    WifiMonitor *wifiMonitorThread;
DECLARE_EVENT_TABLE()
};

const int ID_TOOLBAR = 500;

#endif
/* -----------------------------------------------------------------
 * local variables:
 * eval: (load-file "../rapidsvn-dev.el")
 * end:
 */

